#ifndef MESH_H
#define MESH_H

class Mesh
{
public:
							Mesh( void );
							Mesh( float* vertices, int verticesNum, int* indices, int indicesNum );
	virtual					~Mesh();
	virtual	void			Render( void );
	void					SetPerVertexNormals( float* normals );
	void					SetPerVertexTextureCoords( float* tcoords );
	void					SetAuxInfo( bool value );

private:
	float*					vertices;	
	float*					normals;
	float*					tcoords;
	int						verticesNum;
	//
	int*					indices;
	int						indicesNum;
	bool					auxInfo; // toggling auxiliary info
};

CG_INLINE void Mesh::SetPerVertexNormals( float* normals )
{
	this->normals = normals;
}

CG_INLINE void Mesh::SetPerVertexTextureCoords( float* tcoords )
{
	this->tcoords = tcoords;
}

CG_INLINE void Mesh::SetAuxInfo( bool value )
{
	auxInfo = value;
	if ( auxInfo ) {
		glDisable( GL_LIGHTING );
		glDisable( GL_TEXTURE_2D );
	} else {
		glEnable( GL_LIGHTING );
		glEnable( GL_TEXTURE_2D );
	}
}

class Quad : public Mesh
{
public:
						Quad( const cg::Vec3& origin, const cg::Vec3& x, const cg::Vec3& y );

virtual	void			Render( void );

private:
	cg::Vec3			vertices[ 4 ];
	cg::Vec2			textCoords[ 4 ];
	cg::Vec3			normal;
};

CG_INLINE Quad::Quad( const cg::Vec3& origin, const cg::Vec3& x, const cg::Vec3& y )
{
	vertices[ 0 ] = origin;
	vertices[ 1 ] = origin + x;
	vertices[ 2 ] = origin + x + y;
	vertices[ 3 ] = origin + y;
	//
	normal = x.Cross( y );
	normal.Normalize();
	//
	textCoords[ 0 ] = cg::Vec2::ZERO;
	textCoords[ 1 ] = cg::Vec2::X_AXIS;
	textCoords[ 2 ] = cg::Vec2( 1.0f, 1.0f );
	textCoords[ 3 ] = cg::Vec2::Y_AXIS;	
}

#endif